#pragma once
#include <windows.h>
#include <winbase.h>
#include <vector>
#include <string>
#include "search.h"

using namespace std;

#include "structs.h"

extern int iNumInstances;
extern HINSTANCE hMainInstance;
extern HWND hDlgCurrent;

int literal_u8(u8 *str);
int literal_u16(u8 *str);
int charcase_u8(u8 *str);
int charcase_wide(u8 *str);

class CLanguageHelper
{
public:
	CLanguageHelper();
	//~CLanguageHelper();

	GString LoadString(UINT uID);
	void SetLanguage(WORD lang);

	//HMODULE hModule;
	WORD lang;

	enum Language
	{
		LANG_DEF=MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
		LANG_ENG=MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
		LANG_ITA=MAKELANGID(LANG_ITALIAN, SUBLANG_ITALIAN)
	};
};

inline static GString LoadString(UINT uID)
{
	extern CLanguageHelper lang_helper;
	return lang_helper.LoadString(uID);
}

GString GetWindowText(HWND &hDlg, int nIDDlgItem);
GString LoadString(UINT uID);
//GString LoadFileFilter(UINT uID);
void SetFileDialog(OPENFILENAME &ofn, LPCTSTR filter, LPCTSTR title);
void ReleaseWindowText();
GString GetClipboardText();

LRESULT CALLBACK MainWndProc (HWND, UINT, WPARAM, LPARAM);
void MessageCopyBox(HWND hWnd, LPTSTR lpText, LPCTSTR lpCaption, UINT uType, HWND hwnd);

void count_instances();
//void create_relative_search_string();

//FILE MENU
BOOL CALLBACK OpenPartiallyDialogProc (HWND hDialog, UINT iMsg, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK TmplDisplayDialogProc (HWND hDialog, UINT iMsg, WPARAM wParam, LPARAM lParam);
//SELECTION MENU
BOOL CALLBACK CutDialogProc (HWND hDialog, UINT iMsg, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK CopyDialogProc (HWND hDialog, UINT iMsg, WPARAM wParam, LPARAM lParam);
//BOOL CALLBACK FastPasteDialogProc (HWND hDialog, UINT iMsg, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK PasteDialogProc (HWND hDialog, UINT iMsg, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK SelectBlockDialogProc (HWND hDialog, UINT iMsg, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK FillWithDialogProc (HWND hDialog, UINT iMsg, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK CopyHexdumpDialogProc (HWND hDialog, UINT iMsg, WPARAM wParam, LPARAM lParam);
//OFFSET MENU
//BOOL CALLBACK GoToDialogProc (HWND hDialog, UINT iMsg, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK BitManipDialogProc (HWND hDialog, UINT iMsg, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK ChooseDiffDialogProc (HWND hDialog, UINT iMsg, WPARAM wParam, LPARAM lParam);
//INSERT MENU
BOOL CALLBACK EnterDecimalValueDialogProc (HWND hDialog, UINT iMsg, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK AppendDialogProc (HWND hDialog, UINT iMsg, WPARAM wParam, LPARAM lParam);
//SEARCH MENU
//BOOL CALLBACK FindDialogProc (HWND hDialog, UINT iMsg, WPARAM wParam, LPARAM lParam);
//BOOL CALLBACK FindHexProc (HWND hDialog, UINT iMsg, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK FindWithTableDialogProc (HWND hDialog, UINT iMsg, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK ReplaceDialogProc (HWND hDialog, UINT iMsg, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK ReplaceWithTableDialogProc (HWND hDialog, UINT iMsg, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK SearchRelativeDialogProc (HWND hDialog, UINT iMsg, WPARAM wParam, LPARAM lParam);
//BOOL CALLBACK ScanRelativeDialogProc (HWND hDialog, UINT iMsg, WPARAM wParam, LPARAM lParam);
//BOOL CALLBACK ValScanRelativeDialogProc (HWND hDialog, UINT iMsg, WPARAM wParam, LPARAM lParam);
//BOOKMARK MENU
BOOL CALLBACK AddBookmarkDialogProc (HWND hDialog, UINT iMsg, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK RemoveBookmarkDialogProc (HWND hDialog, UINT iMsg, WPARAM wParam, LPARAM lParam);
//SCRIPT MENU
BOOL CALLBACK TableConvertDialogProc (HWND hDialog, UINT iMsg, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK ScriptDumpDialogProc (HWND hDialog, UINT iMsg, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK ScriptReplaceDialogProc (HWND hDialog, UINT iMsg, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK ViewScriptDialogProc (HWND hDialog, UINT iMsg, WPARAM wParam, LPARAM lParam);
//OPTIONS MENU
//BOOL CALLBACK ViewSettingsDialogProc (HWND hDialog, UINT iMsg, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK CharacterSetDialogProc (HWND hDialog, UINT iMsg, WPARAM wParam, LPARAM lParam);
//BOOL CALLBACK ColorSettingsDialogProc (HWND hDialog, UINT iMsg, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK BinaryModeDialogProc (HWND hDialog, UINT iMsg, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK OffsetModeDialogProc (HWND hDialog, UINT iMsg, WPARAM wParam, LPARAM lParam);
//HELP MENU
//BOOL CALLBACK AboutDialogProc (HWND hDialog, UINT iMsg, WPARAM wParam, LPARAM lParam);
//TOOL BAR
BOOL CALLBACK ToolBarDialogProc (HWND hDialog, UINT iMsg, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK IMEBarDialogProc (HWND hDialog, UINT iMsg, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK ProgressDialogProc (HWND hDialog, UINT iMsg, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK InfoDialogProc (HWND hDialog, UINT iMsg, WPARAM wParam, LPARAM lParam);

#define IN_BOUNDS( i, a, b ) ( ( i >= a && i <= b ) || ( i >= b && i <= a ) )
#define bitval(base,pos) ((base)[(pos)/8]&(1<<((pos)%8)))

int find_bytes_relatively (char* ps, int ls, vector<relation>& offsets, int findstringlength, int mode);
HRESULT ResolveIt( HWND hwnd, LPCTSTR lpszLinkFile, LPWSTR lpszPath );

_tstring FixFilename(LPCTSTR cFileName, LPCTSTR extension);
int intvalue(_tstring &s);
double floatvalue(_tstring &s);
_tstring stringvalue(int n);
_tstring stringvalue(double d);
